#include "Setup.h"

/****************************************************************************/
/*                               E X T E R N S                              */
/****************************************************************************/

extern int currentWindowHeight;
extern int currentWindowWidth;
extern Theme thm;
extern bool runSetup;

/****************************************************************************/
/*                     U T I L I T Y   F U N C T I O N S                    */
/****************************************************************************/

Setup::Setup() {
    setupStep = 1;
    s1t1 = new Text("Welcome to Planner, The Radial Calendar.", 50, 50);
    s1t2 = new Text("Since this is the first time you have used Planner, you will be asked to import a file.", 50, 80);
    s1t3 = new Text("Please place your .ics file in the same foldar as Planner and then click \"Continue\".", 50, 94);
    s1t4 = new Text("I\'ll wait.", 50, 108);

    s2t1 = new Text("Please pick a file to import.", 50, 50);
    s2t2 = new Text("(Don't worry, you can import more than one.)", 50, 70);
    import1 = new Text("Import File 1", 100, 100);
    import2 = new Text("Import File 2", 100, 130);
    import3 = new Text("Import File 3", 100, 160);
    import4 = new Text("Import FIle 4", 100, 190);
    rescan = new Text("Look for New Files", 100, 300);

    s3t1 = new Text("File Successfully Imported.", 50, 50);
    s3t2 = new Text("If you would like, you may import another. Otherwise you can continue.", 50, 80);
    importAnother = new Text("Import Another", 100, 300);
    
    s4t1 = new Text("Setup is complete.", 50, 50);
    finish = new Text ("Finish", 300, 300);
    
    next = new Text("Continue", 300, 300);
}

bool 
Setup::drawSetup(){
    if(setupStep<=0 || setupStep>4) return false;
        
    // clear the screen
    glClearColor(thm.clearColor.r, thm.clearColor.g, thm.clearColor.b, thm.clearColor.t);
    glClear(GL_COLOR_BUFFER_BIT);    
    
    // draw the appropriate step
    switch(setupStep) {
        case 1:
            s1t1->drawPlainText();
            s1t2->drawPlainText();
            s1t3->drawPlainText();
            s1t4->drawPlainText();
            next->drawMenuText();
            break;
        case 2:
            s2t1->drawPlainText();
            s2t2->drawPlainText();
            import1->drawMenuText();
            import2->drawMenuText();
            import3->drawMenuText();
            import4->drawMenuText();
            //rescan->drawMenuText();
            break;
        case 3:
            s3t1->drawPlainText();
            s3t2->drawPlainText();
            next->drawMenuText();
            importAnother->drawMenuText();
            break;
        case 4:
            s4t1->drawPlainText();
            finish->drawMenuText();
            break;
        default:
            return false;
    }
   
    return true;
}

bool
Setup::mouseClickOnButton(int x, int y){
    if(setupStep<=0 || setupStep>4) return false;
    switch(setupStep) {
        case 1:
            if(next->positionIsInMenu(x, y)) setupStep = 2;
            break;
        case 2:
            if(import1->positionIsInMenu(x, y)) setupStep = 3;
            if(import2->positionIsInMenu(x, y)) setupStep = 3;
            if(import3->positionIsInMenu(x, y)) setupStep = 3;
            if(import4->positionIsInMenu(x, y)) setupStep = 3;
            break;
        case 3:
            if(next->positionIsInMenu(x, y)) setupStep = 4;
            if(importAnother->positionIsInMenu(x, y)) setupStep = 2;
            break;
        case 4:
            if(finish->positionIsInMenu(x, y)) runSetup = false;
            break;
        default:
            return false;
    }
    return true;
}
